package cn.sycoder.dto;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.util.Date;

@Data
@Builder
@ApiModel(value = "Product对象", description = "")
public class ProductDto {
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @ApiModelProperty("产品名称")
    private String name;

    @ApiModelProperty("历史入库总量")
    private Integer inventorySum;

    @ApiModelProperty("库存值")
    private Integer inventory;

    @ApiModelProperty("出库总值")
    private Integer inventoryRemove;

    @ApiModelProperty("单位")
    private String unit;

    @ApiModelProperty("库房地址多个存储用 ，号隔开如： 库房，位置，位置编号")
    private String location;

    @ApiModelProperty("1告警0是正常")
    private Integer alarm;

    @ApiModelProperty("物件编号")
    private String code;

    @ApiModelProperty("警告值 库存值低于警告值告警提示")
    private Integer alarmValue;

    @ApiModelProperty("型号")
    private String type;

    @ApiModelProperty("产品图片地址")
    private String img;

    @ApiModelProperty("状态 1开启，0删除")
    private Integer statusCode;

    @ApiModelProperty("创建用户")
    private String createUser;

    // 自动填充
    @TableField(value = "create_time",fill = FieldFill.INSERT)
    @ApiModelProperty("创建时间")
    private Date createTime;

    @ApiModelProperty("更新人")
    private String updateUser;

    // 自动填充
    @TableField(value = "update_time",fill = FieldFill.UPDATE)
    @ApiModelProperty("更新时间")
    private Date updateTime;

    @ApiModelProperty("库房地址")
    private String storeHouse;

    @ApiModelProperty("具体位置")
    private String site;

    @ApiModelProperty("Jwt令牌")
    private String token;

    public void setLocation(String location){
        if (!StringUtils.isEmpty(location)){
            String[] split = location.split(",");
            String storeHouse = split[0]; // 获取逗号分割后左边的值
            this.storeHouse = storeHouse;
            String site = split[1]; // 获取逗号分割后右边的值
            this.site = site;
        }
        this.location = location;
    }
}
